package deepbitview

import org.apache.tools.ant.taskdefs.optional.Cab

/**
 * synchronizes the database with the online service all 10 minutes and fetches so the updated statistics
 * to be used in this system
 */
class SynchronizeJob {

    /**
     * this trigger defines that this method will be executed all 10 minutes after an initial 60 second delay
     */

    static triggers = {
        simple name: 'synchronizeTrigger', startDelay: 60000, repeatInterval: ActiviationKeyHandler.getSampleRateInMinutes() * 60000
    }

    DeepViewAccessService deepViewAccessService

    /**
     * start the synchronization
     * @return
     */
    def execute() {

        try {
            if (ActiviationKeyHandler.isKeyRegistered()) {
                deepViewAccessService.receiveDataWithDefaultKey()
            }
            else{
                println "sorry no key registered!"
            }
        }
        catch (Exception e) {
            log.warn(e.getMessage(), e)
        }
    }
}
